package com.woniuxy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.dao.QuestionInventoryMapper;
import com.woniuxy.entity.QuestionInventory;
import com.woniuxy.service.QuestionInventoryService;
import org.springframework.beans.factory.annotation.Autowired;
import com.woniuxy.entity.ResponseEntity;

import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @Description: TODO
 * @Author: HeMinghong
 * @CreateTime: 2022-06-01  16:03
 * @Version: 1.0
 */
@Service
public class QuestionInventoryServiceImpl implements QuestionInventoryService {
    QuestionInventoryMapper questionInventoryMapper;

    @Autowired(required = false)
    public QuestionInventoryServiceImpl(QuestionInventoryMapper questionInventoryMapper) {
        this.questionInventoryMapper = questionInventoryMapper;
    }

    @Override
    public ResponseEntity findAll() {
        PageHelper.startPage(5,10);
        List<QuestionInventory> all= questionInventoryMapper.findAllSubject();
        PageInfo<QuestionInventory> of = PageInfo.of(all);
        ResponseEntity responseEntity = new ResponseEntity(of);
        return responseEntity;
    }

    @Override
    public ResponseEntity updateOne(QuestionInventory questionInventory) {
        questionInventory.setUpdateTime(new Date());
        int i = questionInventoryMapper.updateOne(questionInventory);
        if (i > 0) {
            return ResponseEntity.SUCCESS;
        }else {
            return ResponseEntity.ERROR;
        }
    }

    @Override
    public ResponseEntity deleteOne(QuestionInventory questionInventory) {
        int i = questionInventoryMapper.deleteOne(questionInventory.getId());
        if (i > 0) {
            return ResponseEntity.SUCCESS;
        }else {
            return ResponseEntity.ERROR;
        }
    }

    @Override
    public ResponseEntity addOne(QuestionInventory questionInventory) {
        Date date=new Date();
        questionInventory.setAddTime(date);
        questionInventory.setUpdateTime(date);
        int i = questionInventoryMapper.addOne(questionInventory);
        if (i > 0) {
            return ResponseEntity.SUCCESS;
        }else {
            return ResponseEntity.ERROR;
        }
    }

    @Override
    public List<QuestionInventory> findInventories() {
        return questionInventoryMapper.findInventories();
    }

    @Override
    public ResponseEntity findAllSubjects2() {
        PageHelper.startPage(5,10);
        List<QuestionInventory> all= questionInventoryMapper.findAllSubject();
        PageInfo<QuestionInventory> of = PageInfo.of(all);
        ResponseEntity responseEntity = new ResponseEntity(of);
        return responseEntity;
    }
    @Override
    public List<QuestionInventory> findAllSubjects() {

        List<QuestionInventory> all= questionInventoryMapper.findAllSubject();

        return all;
    }

    @Override
    public ResponseEntity findById(Integer id) {
        return new ResponseEntity(questionInventoryMapper.findById(id));
    }

    @Override
    public QuestionInventory findBySubject(String subject) {
        return questionInventoryMapper.findBySubject(subject);
    }

    @Override
    public List<QuestionInventory> findAllSonSubjectById(Integer id) {
        return questionInventoryMapper.findAllSonSubject(id);
    }


}
